﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.RateLimiting;

namespace Magic.Web.Entry;

/// <summary>
/// 认证服务
/// </summary>

public class AuthController : BaseController
{
    private readonly IAuthService _service;
    public AuthController(IAuthService service)
    {
        _service = service;
    }

    /// <summary>
    /// 登录
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost("/admin/index/login")]
    [AllowAnonymous]
    public async Task<LoginOutput> Login(LoginInput input)
    {
        return await _service.Login(input);
    }
    /// <summary>
    /// 验证码
    /// </summary>
    /// <returns></returns>
    [HttpGet("/admin/index/login")]
    [AllowAnonymous]
    public async Task<dynamic> GetLogin()
    {
        return new { Captcha = false };
    }
    /// <summary>
    /// 登录人员信息
    /// </summary>
    /// <returns></returns>
    [HttpGet("/admin/index/index")]
    public async Task<LoginUserInfoOutput> Index() {
        return await _service.GetLoginUserInfo();
    }

    /// <summary>
    /// 退出登录
    /// </summary>
    /// <returns></returns>
    [HttpPost("/admin/index/logout")]
    public async Task Logout()
    {
        await _service.Logout();
    }
}
